package {
	
	import flash.net.SharedObject;
	import flash.net.SharedObjectFlushStatus;
	import mx.controls.Alert;
	import flash.events.NetStatusEvent;
	import mx.utils.ObjectUtil;

	import my1flex;
	import def;
	 
	[Bindable]
	public dynamic class LocalConf extends Object {
		
		public var data:LocalConfData = new LocalConfData();
		//public var data;
		public var confDataDef;
		
		public var _name:String;
		
		
		public function loadConf(){
						
			 	var loc:SharedObject = SharedObject.getLocal(_name);
			 	
			 	
				confDataDef = ObjectUtil.copy(data);
				   
				if (loc.data.locConf && loc.data.locConf._verConf && loc.data.locConf._verConf == data._verConf){ 
					   //my1flex.cpyob(data, loc.data.locConf);
					   //Alert.show(data);
					   //Alert.show(loc.data.locConf[_name].widthMainTree);
					   	var rr:Object = ObjectUtil.copy(loc.data.locConf);
						//my1flex.dumpl(rr,'rrrrrrrrrrrr');		
					   
					   //for (var i in rr)
					   //		if (rr[i] != undefined) data[i] = rr[i];
					   
					   my1flex.cpyob(data, rr);
					   
					}  
					  else { 
						   loc.clear();
					  }
					  
			   }
			 
			
			public function saveConf(fun = null){
				var loc:SharedObject = SharedObject.getLocal(_name);
				loc.data.locConf = data;
				/*loc.dataloc.data.locConf= {};
				for (var i in confDataDef){
				 	Alert.show(i);
				 	loc.data[_name][i] = this[i];
				}*/
				var stat = loc.flush();
				 
				if (fun){
					var onFlash = function(e){
						switch (e.info.code) {
			                case "SharedObject.Flush.Success":
			                case "SharedObject.Flush.Failed":
			                    fun.call();
			            }
						
						loc.removeEventListener(NetStatusEvent.NET_STATUS, onFlash);
					};
					if (stat == SharedObjectFlushStatus.PENDING)
						loc.addEventListener(NetStatusEvent.NET_STATUS, onFlash);
							else fun.call(); 	
				}
				//loc.data[_name]['widthMainTree'] = this['widthMainTree'];
			}
			
			
  		   
  		   public function setDef(prop = null){
  		   		
				//if (commandUser[0])
				//	my1flex.dumpl(commandUser, commandUserPos);		   
  		   	 /*
	  		   	if (prop) {
	  		   	  	if (typeof confDataDef[prop]  == 'object')   my1flex.cpyob(this[prop], confDataDef[prop]);
	  		   	  	 		else  this[prop] = confDataDef[prop];
	  		   	} else 
	  		   		 my1flex.cpyob(this, confDataDef);
	  		   */		 
	
	  		   	
				if (prop){ 
					  var par:Object = ObjectUtil.copy(confDataDef[prop]);
	  		   	  	  data[prop] = par[prop];
					}
	  		   		else {
		  		   	   var rr:Object = ObjectUtil.copy(confDataDef);
					   for (var i in rr)
					   			data[i] = rr[i];
	  		   		}
		}
		
			
			
			function LocalConf(){
				 	_name = def.NAME_LOCAL_CONF;
				 	super();
					loadConf();
					
			}
							
				
	}
}

